
package com.pj.api.controller;


import cn.dev33.satoken.stp.StpUtil;
import com.pj.project.entity.LoginForm;
import com.pj.utils.sg.AjaxJson;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * APP登录授权
 *
 * @author Mark sunlightcs@gmail.com
 */
@RestController
@RequestMapping("/app")
@Api(tags = "登陆")
public class AppLoginController {

    /**
     * 登录
     */
    @PostMapping("login")
    @ApiOperation("登陆")
    public AjaxJson login(@RequestBody LoginForm form){
        StpUtil.login(form.getMobile());
        Map<String, Object> map = new HashMap<>();
        map.put("token", StpUtil.getTokenValue());
        map.put("expire", StpUtil.getTokenActivityTimeout());

        return AjaxJson.getSuccess("登陆成功",map);
    }

    /**
     * 退出
     */
    @PostMapping("logout")
    @ApiOperation("退出")
    public AjaxJson logout(){
        StpUtil.logout();
        return AjaxJson.getSuccess("成功");
    }
}
